package plugin

import (
	"net/rpc"
)

// 代理实现RPC
type Plugin_RpcClient struct {
	Client *rpc.Client
}

func (s *Plugin_RpcClient) SetParam(configContext, peerUrl, orgId, userId string) string {
	var resp string

	var x interface{} = []string{configContext, peerUrl, orgId, userId}
	err := s.Client.Call("Plugin.SetParam", &x, &resp)
	if err != nil {
		return Exit(201, err.Error(), nil)
	}
	return resp
}

func (s *Plugin_RpcClient) GetChannels() string {
	var resp string

	var x interface{} = nil
	err := s.Client.Call("Plugin.GetChannels", &x, &resp)
	if err != nil {
		return Exit(201, err.Error(), nil)
	}

	return resp
}

// 概要
func (s *Plugin_RpcClient) GetSummaryInfo(bReq []byte) string {
	var resp string

	var x interface{} = bReq
	err := s.Client.Call("Plugin.GetSummaryInfo", &x, &resp)
	if err != nil {
		return Exit(201, err.Error(), nil)
	}
	return resp
}

func (s *Plugin_RpcClient) GetBlockInfo(bReq []byte) string {
	var resp string

	var x interface{} = bReq
	err := s.Client.Call("Plugin.GetBlockInfo", &x, &resp)
	if err != nil {
		return Exit(201, err.Error(), nil)
	}
	return resp
}

func (s *Plugin_RpcClient) GetTransactionInfo(bReq []byte) string {
	var resp string

	var x interface{} = bReq
	err := s.Client.Call("Plugin.GetTransactionInfo", &x, &resp)
	if err != nil {
		return Exit(201, err.Error(), nil)
	}
	return resp
}
